package com.bdqn.t320.ch12.service;

import com.bdqn.t320.ch12.entity.Right;
import com.bdqn.t320.ch12.entity.Role;
import com.bdqn.t320.ch12.repository.RightRepository;
import com.bdqn.t320.ch12.repository.RoleRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServiceImp implements RoleService {

    @Resource
    RoleRepository roleRepository;

    @Resource
    RightRepository rightRepository;


    //@CachePut  修改
    //@CacheEvict  删除
    //@Cacheable(value = "role", keyGenerator = "keyGenerator")
    //@CacheEvict(value = "role", keyGenerator = "keyGenerator")
    @Override
    //@RequiresPermissions(value = "用户编辑")
    public List<Role> getRoleListService(Sort sort) {
        return roleRepository.findAll(sort);
    }

    @Override
    public List<Right> findAllRights() {
        return rightRepository.findAll();
    }

    @Override
    public List<Right> findRightsByRole(Role role) {
        return rightRepository.findRightsByRolesOrderByRightCode(role);
    }
}
